#ifndef COMB_CALL_RATES_HPP__
#define COMB_CALL_RATES_HPP__

#include "util.hpp"
#include "perm_parser.hpp"
#include "sam_parser.hpp"
#include "snp_cand.hpp"
#include "serialization.hpp"
#include "option_parse.hpp"
#include "qual.hpp"

#include <iostream>

/** Read the color call rates structure from a file.  The rates are processed into a reindexed table.  Accessing qual_bins[position][original_score] will give the new bin.
 * \param call_counts The frequency matrix of observed scores.
 * \param call_rates The data structure to be populated.
 * \param obc old bin count. 
 * \param nbc new bin count.
 * \param read_length Read length.
 * \param qual_bins The reindexing structure.
 */
void process_color_counts_to_rates(array_type5 &call_counts, array_type5 &call_rates, int obc, int nbc, int read_length, boost::multi_array<int, 2> &qual_bins);

/** Calculate the call rates structure, skipping positions that are SNP candidates in color space. 
 * \param options Options that the program was called with.
 * \param calls The call rates to be populated.
 * \param cand_blocks SNP candidates.
 * \param snp_cands SNP candidates.
 */
void find_call_rates(prog_options &options, array_type5 &calls, cand_blocks_t &cand_blocks, cand_vector_t &snp_cands);

/** Calculate the call rates structure, using all reads when in color space.
 * \param options Options the program was called with.
 * \param calls Call rates data structure to be populated.
 */
void find_call_rates_no_cand(prog_options &options, array_type5 &calls);

/** Driver for "comb callrates"
 */
void do_callrates(int argc, char **argv);

/** Driver for "comb callrates" when in color space.
 */
void do_color_callrates(prog_options &options);

/** Driver for "comb callrates" when in sequence space.
 */
void do_seq_callrates(prog_options &options);

/** Calculate the call rates structure, skipping positions that are snp candidates in sequence space.
 * \param options Options comb was called with.
 * \param calls The call rates to be populated.
 * \param cand_blocks SNP candidates
 * \param snp_cands SNP candidates
 */
void find_seq_call_rates(prog_options &options, array_type4 &calls, cand_blocks_t &cand_blocks, cand_vector_t &snp_cands);

/** Calculate the call rates structure, using all reads in sequence space.
 * \param options Options comb was called with.
 * \param calls The call rates to be populated.
 */
void find_seq_call_rates_no_cand(prog_options &options, array_type4 &calls);

/** Load the call rates for sequence space problem.
 * \param call_counts The frequencies of observed qualities in the reads.
 * \param call_rates The data structure to be populated.
 * \param obc old bin count. 
 * \param nbc new bin count.
 * \param read_length Read length.
 * \param qual_bins The reindexing structure.
 */
void process_seq_counts_to_rates(array_type4 &call_counts, array_type4 &call_rates, int obc, int nbc, int read_length, boost::multi_array<int, 2> &qual_bins);

void fill_call_priors_seq(prog_options &options, array_type4 &calls);
void fill_call_priors(prog_options &options, array_type5 &calls);
#endif
